package com.java2207.group1.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.java2207.group1.bo.DinnerBo;
import com.java2207.group1.bo.LunchBo;
import com.java2207.group1.pojo.Dinner;
import com.java2207.group1.pojo.Lunch;
import com.java2207.group1.service.DinnerService;
import com.java2207.group1.service.LunchService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @author AL 2022/7/27  8:48
 */
@Component
@Scope("prototype")//这里设置成多例模式
public class WebDinnerListener extends AnalysisEventListener<DinnerBo> {


    @Autowired
    private DinnerService dinnerService;

    @Override
    public void invoke(DinnerBo data, AnalysisContext analysisContext) {
        Dinner dinner = new Dinner();
        BeanUtils.copyProperties(data,dinner);
        dinnerService.addDinner(dinner);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
